package com.yunhe.java.day03;

import java.util.Scanner;

/**计算两年相隔天数
 * Created by Administrator on 2017/7/20 0020.
 */
public class Date {

    public static void main(String[] args) {
        Scanner scanner=new Scanner(System.in);
        System.out.println("请输入a");
        int a = scanner.nextInt();
        System.out.println("请输入b");
        int b = scanner.nextInt();
        System.out.println("请输入c");
        int c = scanner.nextInt();
        System.out.println("请输入d");
        int d= scanner.nextInt();
        System.out.println("请输入e");
        int e= scanner.nextInt();
        System.out.println("请输入f");
        int f = scanner.nextInt();
        int day1=calcDate(a,b,c);
        int day2=calcDate(d,e,f);
        System.out.println(day1);
        System.out.println(day2);
        int sum=0;
        for(int i=a+1;i<d;i++){
            if((i%4==0)&&(i%100!=0)||i%400==0){
                sum+=366;
            }else {
                sum+=365;
            }
        }
        if ((a % 4 == 0) && (a % 100 != 0) || a % 400 == 0){
            int day=366-day1;
        }else {
            int day = 365 - day1;
            if(a==d){
                System.out.println( day2-day1);
            }else{
            System.out.println(day + sum + day2);}
        }
        }

    public static int calcDate(int year, int month, int day) {
        int total = 0;
        for (int i = 1; i < month; i++) {
            int days;
            switch (i) {
                case 1:
                case 3:
                case 5:
                case 7:
                case 8:
                case 10:
                case 12: {
                    days = 31;
                }
                break;
                case 2: {
                    days = 28;
                    if ((year % 4 == 0) && (year % 100 != 0) || year % 400 == 0) {
                        days = 29;
                    }
                }break;
                case 4:
                case 6:
                case 9:
                case 11: {
                    days = 30;
                    break;
                }
                default:days = 30;
            }

            total += days;
        }

        return total + day;
    }
}

